@extends('admin.layout.global')

@section('css-plugins')
    <link href="{{ asset('style/plugins/chosen_v1.2.0/chosen.min.css') }}" rel="stylesheet">
    <link href="{{ asset('style/plugins/daterangepicker/daterangepicker.css') }}" rel="stylesheet">
@endsection

@section('css')
    <link href="{{ asset('style/admin/css/custom.css') }}" rel="stylesheet">
    <style>
        .pagination {
            margin: 0 0;
        }
        .form-group {
            margin-bottom: 0;
        }
    </style>
@endsection

@section('js-plugins')
    <script src="{{ asset('style/plugins/chosen_v1.2.0/chosen.jquery.min.js') }}"></script>
    <script src="{{ asset('style/plugins/moment/moment.js') }}"></script>
    <script src="{{ asset('style/plugins/daterangepicker/daterangepicker.js') }}"></script>
@endsection

@section('js')
    <script src="{{ asset('style/admin/js/pages/blankon.form.element.js') }}"></script>
    <script>
        $(function(){
            var menu = $(".dropdown-menu").find("a");
            menu.click(function(){
                var text = $(this).text();
                var k = $(this).data('key');
                $('#showKey').text(text);
                $('#searchType').val(k);
            });
        });
    </script>
    <script>
        $(document).ready(function () {
            //定义
            var $groupID        = $("select[name='groupID']");
            var $time           = $("input[name='time']");
            //查询
            function getQuery() {
                var groupID         = $groupID.val();
                var time            = $time.val();
                console.log(time);
                var separator       = '?';
                var url = '{{ action('Admin\MemberController@getIndex') }}';
                if (groupID != '')
                {
                    url += separator + 'groupID=' + groupID;
                    separator = '&';
                }
                if (time != '')
                {
                    url += separator + 'time=' + time;
                }
                window.location = url;
            }
            $('#dateTime').daterangepicker({
                "autoUpdateInput": false,
                "timePicker": true,
                "timePicker24Hour": true,
                "timePickerSeconds": true,
                "timePickerIncrement": 1,
                "locale": {
                    "format": "YYYY-MM-DD HH:mm:ss",
                    "separator": " - ",
                    "applyLabel": "提交",
                    "cancelLabel": "取消",
                    "fromLabel": "From",
                    "toLabel": "To",
                    "customRangeLabel": "Custom",
                    "daysOfWeek": [
                        "日",
                        "一",
                        "二",
                        "三",
                        "四",
                        "五",
                        "六"
                    ],
                    "monthNames": [
                        "一月",
                        "二月",
                        "三月",
                        "四月",
                        "五月",
                        "六月",
                        "七月",
                        "八月",
                        "九月",
                        "十月",
                        "十一月",
                        "十二月"
                    ],
                    "firstDay": 1,
                },
                "drops": "down"
            }, function(start, end, label) {
            });
            $('#dateTime').on('apply.daterangepicker', function(ev, picker) {
                $(this).val(picker.startDate.format('YYYY-MM-DD HH:mm:ss') + " - " + picker.endDate.format('YYYY-MM-DD HH:mm:ss'));
                getQuery();
            });
            @if(isset($_GET['time']) && $_GET['time'] != '')
            @else
            $('#dateTime').val('');
            @endif
            $('.inputSelect').change(function(){
                getQuery();
            });
        });
    </script>
@endsection


@section('content')
    <div class="body-content animated fadeIn">
        <div class="row">
            <div class="col-md-12">
                <!-- Start inline form -->
                <div class="panel rounded shadow">
                    <div class="panel-body no-padding">
                        <div class="form-horizontal mt-10">
                            <div class="form-body">
                                <div class="form-group">
                                    <div class="col-sm-2">
                                        <select data-placeholder="{{ getLang('fieldsMember', 'groupHelp') }}" name="groupID" class="chosen-select mb-15 inputSelect" tabindex="2">
                                            <option value="">{{ getLang('fieldsMember', 'allGroup') }}</option>
                                            @foreach($memberGroup as $v)
                                                <option value="{{ $v->id }}" @if(isset($_GET['groupID']) && $_GET['groupID'] == $v->id) selected @endif>{{ $v->name }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-sm-3">
                                        <input id="dateTime" class="form-control inputSelect" name="time" type="text" value="@if(isset($_GET['time']) && $_GET['time'] != ''){{ $_GET['time'] }}@endif" placeholder="{{ getLang('fieldsMember', 'time') }}" />
                                    </div>
                                    <div class="col-sm-3"></div>
                                    <div class="col-sm-4">
                                        <form method="get">
                                        <div class="input-group mb-15">
                                            <div class="input-group-btn">
                                                <?php
                                                    function getKeyName($name){
                                                        switch ($name){
                                                            case 'id':
                                                                $keyName = getLang('fieldsMember', 'id');
                                                                break;
                                                            case 'email':
                                                                $keyName = getLang('fieldsMember', 'emailHelp');
                                                                break;
                                                            case 'name':
                                                                $keyName = getLang('fieldsMember', 'username');
                                                                break;
                                                            case 'realName':
                                                                $keyName = getLang('fieldsMember', 'nickname');
                                                                break;
                                                            default:
                                                                $keyName = getLang('fieldsMember', 'id');
                                                        }
                                                        return $keyName;
                                                    }
                                                ?>
                                                <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle" type="button"><span id="showKey">{{ isset($_GET['searchType']) ? getKeyName($_GET['searchType']) : 'ID' }}</span> <span class="caret"></span></button>
                                                <ul class="dropdown-menu">
                                                    <li><a data-key="id">{{ getLang('fieldsMember', 'id') }}</a></li>
                                                    <li><a data-key="email">{{ getLang('fieldsMember', 'emailHelp') }}</a></li>
                                                    <li><a data-key="name">{{ getLang('fieldsMember', 'username') }}</a></li>
                                                    <li><a data-key="realName">{{ getLang('fieldsMember', 'nickname') }}</a></li>
                                                </ul>
                                            </div>
                                            <input id="searchType" name="searchType" value="{{ isset($_GET['searchType']) ? $_GET['searchType'] : 'id' }}" type="hidden">
                                            <input name="keyword" value="{{ isset($_GET['keyword']) ? $_GET['keyword'] : '' }}" class="form-control no-border-left" type="text">
                                            <span class="input-group-btn"><button type="submit" class="btn btn-success"><i id="icoico" class="fa fa-search"></i></button></span>
                                        </div>
                                        </form>
                                    </div>
                                </div><!-- /.form-group -->
                            </div><!-- /.form-body -->
                        </div>

                    </div><!-- /.panel-body -->
                </div><!-- /.panel -->
                <!--/ End inline form -->
                <!-- Start basic color table -->
                <div class="panel">
                    <div class="panel-heading">
                        <div class="pull-left">
                            <a href="{{ action('Admin\MemberController@getAdd') }}" class="btn btn-success btn-sm"><i class="fa fa-user-plus"></i> {{ getLang('Tips', 'create') }}</a>
                        </div>
                        <div class="clearfix"></div>
                    </div><!-- /.panel-heading -->
                    <div class="panel-body no-padding">
                        <div class="table-responsive" style="margin-top: -1px;">
                            <table class="table table-striped table-success">
                                <thead>
                                <tr>
                                    <th class="text-center border-right" style="width: 5%">{{ getLang('fieldsMember', 'id') }}</th>
                                    <th>{{ getLang('fieldsMember', 'nickname') }}</th>
                                    <th>{{ getLang('fieldsMember', 'username') }}</th>
                                    <th>{{ getLang('fieldsMember', 'group') }}</th>
                                    <th>{{ getLang('fieldsMember', 'email') }}</th>
                                    <th>{{ getLang('fieldsMember', 'lastLogin') }}</th>
                                    <th class="text-center" style="width: 12%;">{{ getLang('Tips', 'operation') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($members as $v)
                                    <?php
                                        $thumb = parse_url($v->thumb);
                                        if($thumb['scheme'] == 'http' || $thumb['scheme'] == 'https')
                                        {
                                        }else{
                                            $v->thumb = action('ImgController@getMember', ['uid' => $v->id, 'sourceName' => $v->thumb, 'size' => '20x20']);
                                        }
                                    ?>
                                    <tr>
                                        <td class="text-center border-right">{{ $v->id }}</td>
                                        <td>
                                            <img src="{{ $v->thumb }}" width="22" alt="{{ $v->realName ? $v->realName : $v->name }}">
                                            <span>{{ $v->realName ? $v->realName : $v->name }}</span>
                                        </td>
                                        <td>{{ $v->name }}</td>
                                        <td><span class="label" style="background-color: {{ isset($memberGroup[$v->groupID]) ? $memberGroup[$v->groupID]->color : null }}">{{ isset($memberGroup[$v->groupID]) ? $memberGroup[$v->groupID]->name : null }}</span></td>
                                        <td>{{ $v->email }}</td>
                                        <td>{{ $v->updated_at }}</td>
                                        <td class="text-center">
                                            <a href="{{ action('Admin\MemberController@getEdit', ['id' => $v->id]) }}" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="top" data-original-title="{{ getLang('Tips', 'edit') }}"><i class="fa fa-pencil"></i></a>
                                            <button data-url="{{ action('Admin\MemberController@getDel', ['id' => $v->id]) }}" data-tips='{{ getLang('Tips', 'isDelete') }} : {{ $v->realName ? $v->realName : $v->name }}' class='btn btn-danger btn-xs delete-table' data-toggle="tooltip" data-placement="top" data-original-title="{{ getLang('Tips', 'delete') }}"><i class="fa fa-times"></i></button>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div><!-- /.table-responsive -->
                    </div><!-- /.panel-body -->
                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-md-12">
                                <div style="text-align: center">
                                    {!! $members->render() !!}
                                </div>
                            </div>
                        </div>
                    </div>
                </div><!-- /.panel -->
                <!--/ End basic color table -->

            </div><!-- /.col-md-12 -->
        </div>
    </div>
@endsection